import sys
sys.path.append("../")
import requests
import time
from frameworks.cores.LoadClass import *

loader = LoadClass()

from controller.CommonController import *

con = CommonController({"func":"getAllData","model":"ab2_1","fields":["*"],"data":"id > 1104"})
data = con.run()
for row in data:
    print(row)

    item1 = row["item1"].strip()
    item2 = row["item2"].strip()
    item3 = row["item3"].strip()
    item4 = row["item4"].strip()
    if item1 == "":
        item1 = "正确"
        item2 = "错误"
    if item1 == "正确" or item1 == "错误" or item1 == "":
        qtype = "判断题"
        content = "A||"+item1+"|||B||"+item2
    elif len(item1) > 2 and len(row["answer"]) == 1:
        qtype = "单选题"
        content = "A||" + item1 + "|||B||" + item2 + "|||C||" + item3 + "|||D||" + item4
    elif len(item1) > 2 and len(row["answer"]) > 1:
        qtype = "多选题"
        content = "A||" + item1 + "|||B||" + item2 + "|||C||" + item3 + "|||D||" + item4

    fileoption = row["url"].split("/")
    filename = fileoption[len(fileoption) - 1]
    if filename == "":
        other_comment = ""
    else:
        other_comment = "/images/ab2_1/" + filename
    info = {
        "qid":"jiashizheng_ab2_1_"+str(row["id"]),
        "question_group_id":32,
        "question_group_name":"ab2_1",
        "qtype":qtype,
        "title":row["question"],
        "content":content,
        "answer":row["answer"].replace("1","A").replace("2","B").replace("3","C").replace("4","D"),
        "explains":row["explains"],
        "other_comment":other_comment
    }
    rs = loader.load("controller.CommonController", "CommonController", {
        "func": "add",
        "data": info,
        "model": "questions_jiashizheng_ab2_1"
    })
    print(rs)




